package com.yy.watchmen.utils

import android.os.Handler
import android.os.Looper
import android.os.Message
import java.lang.ref.WeakReference

/**
 * @author ligang
 * @Description: 弱引用Handler
 * @CreateDate: 2024/5/4
 */
class WeakReferenceHandler(iHandler: IHandler) : Handler(Looper.getMainLooper()) {
    private val mRef: WeakReference<IHandler> = WeakReference(iHandler)

    override fun handleMessage(msg: Message) {
        super.handleMessage(msg)
        mRef.get()?.handleMessage(msg)
    }

    interface IHandler {
        fun handleMessage(msg: Message)
    }
}